#include "blockqueue.hpp"


#include <ctime>


//生产者
void* producter(void* argc)
{
    BlockQueue<int>* bkque=(BlockQueue<int>*) argc;
    //生产数据
    while(true)
    {
        int num = rand()%100;
        bkque->push(num);
        cout<<"num: "<<num<<"   ";
        cout<<"producter tid: "<<pthread_self()<<endl;
        sleep(1);
    }
}

//消费者
void* consumer(void* argc)
{
    BlockQueue<int>* bkque=(BlockQueue<int>*) argc;
    while(true)
    {
        int num=bkque->pop();
        cout<<"num: "<<num<<"   ";
        cout<<"consumer tid: "<<pthread_self()<<endl;
        sleep(1);
    }

}


int main()
{

    //随机数种子
    srand((unsigned int) time(nullptr));
    BlockQueue<int> bkque;

    pthread_t cons,proc;
    pthread_create(&cons,nullptr,consumer,&bkque);
    pthread_create(&proc,nullptr,producter,&bkque);

    pthread_join(cons,nullptr);
    pthread_join(proc,nullptr);
    
    return 0;
}